/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import junit.framework.TestCase;

import java.text.ParseException;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class ProxyAuthenticateHeaderParserTest extends TestCase {
    public ProxyAuthenticateHeaderParserTest(String name) {
        super(name);
    }

    public void test() {
        final byte[] bytes = "Proxy-Authenticate: Digest realm=\"jcp.org\",domain=\"sip:ss1.duke.com\", qop=\"auth\", nonce=\"f84f1cec41e6cbe5aea9c8e88d359\", opaque=\"\", stale=FALSE, algorithm=MD5".getBytes();
        final ProxyAuthenticateHeaderParser parser = new ProxyAuthenticateHeaderParser();
        ProxyAuthenticateHeaderImpl[] headers;
        try {
            headers = parser.parse(bytes, 19, bytes.length);
        } catch (ParseException e) {
            fail(e.getMessage());
            return;
        }
        assertNotNull("The result is null!", headers);
        assertEquals("The length of the result is wrong!", 1, headers.length);

        assertEquals("The algorithm is wrong!", "MD5", headers[0].getAlgorithm());
        assertEquals("The realm is wrong!", "jcp.org", headers[0].getRealm());
        assertEquals("The domain is wrong!", "sip:ss1.duke.com", headers[0].getDomain());
        assertEquals("The qop is wrong!", "auth", headers[0].getQop());
        assertEquals("The nonce is wrong!", "f84f1cec41e6cbe5aea9c8e88d359", headers[0].getNonce());
        assertEquals("The opaque is wrong!", "", headers[0].getOpaque());
        assertFalse("The stale is wrong!", headers[0].isStale());
        assertEquals("The string representation is wrong!", "Proxy-Authenticate: Digest nonce=\"f84f1cec41e6cbe5aea9c8e88d359\",qop=\"auth\",realm=\"jcp.org\",opaque=\"\",domain=\"sip:ss1.duke.com\",stale=FALSE,algorithm=MD5", headers[0].toString());
    }
}
/*
 * $Log$
 */